Use case: IRDA communication in polling mode

This use case shows how to transmit or receive IRDA data in polling mode. In HAL2, IRDA support is handled via the HAL UART driver.

Sequence diagram

    @startuml
    participant "Application" as p1
    participant "HAL IRDA driver" as p2

    == initialization and configuration ==

    == IRDA Processing in polling mode ==
    alt polling
    p1->p2: HAL_IRDA_Transmit(&hirda,\n                                aTxBuffer,\n                                DATA_TO_SEND_SIZE,\n                                100)
    note over p2 #00FF00
    Transmitting data ongoing
    end note

    p2-->p1: <color #Green> HAL_OK
    else
    p1->p2: HAL_IRDA_Receive(&hirda,\n                                aRxBuffer,\n                                DATA_TO_RECEIVE_SIZE,\n                                100)
    note over p2 #00FF00
    Receiving data ongoing
    end note
    p2-->p1: <color #Green> HAL_OK
    end

    @enduml

Code snippet

HAL1

HAL2

#define DATA_TO_SEND_SIZE            256
#define DATA_TO_RECEIVE_SIZE         DATA_TO_SEND_SIZE

uint8_t aTxBuffer[] = " **** IRDA Communication **** ";
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

IRDA_HandleTypeDef hirda;

HAL_IRDA_Init(&hirda);

(void)HAL_IRDA_Receive(&hirda, aRxBuffer, DATA_TO_RECEIVE_SIZE, 100);
(void)HAL_IRDA_Transmit(&hirda, aTxBuffer, DATA_TO_SEND_SIZE, 100);
#define DATA_TO_SEND_SIZE            256
#define DATA_TO_RECEIVE_SIZE         DATA_TO_SEND_SIZE

uint8_t aTxBuffer[] = " **** IRDA Communication **** ";
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

hal_uart_handle_t huart;
hal_uart_irda_config_t uart_irda_config;

HAL_UART_Init(&huart, HAL_UART4);

/* Configure IRDA mode on the UART instance */
HAL_UART_IRDA_SetConfig(&huart, &uart_irda_config);

(void)HAL_UART_Receive(&huart, aRxBuffer, DATA_TO_RECEIVE_SIZE, 100);
(void)HAL_UART_Transmit(&huart, aTxBuffer, DATA_TO_SEND_SIZE, 100);

Key changes

  1. In HAL2, the standalone IRDA driver is removed; use the HAL UART driver with IRDA configuration.

  2. API names are updated from HAL_IRDA_* to HAL_UART_*.